<!DOCTYPE html>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>设备编辑</title>
    {% include 'admin/common/header.html' %}
</head>
<body>
<form class="layui-form" action="">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item">
                    <label class="layui-form-label">设备编号</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{ doors_equip.code }}" name="code" lay-verify="title"
                               autocomplete="off" placeholder="请输入标题" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">SN码</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{ doors_equip.sn }}" name="sn" lay-verify="title"
                               autocomplete="off" placeholder="请输入标题" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">设备名称</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{ doors_equip.name }}" name="name" lay-verify="title"
                               autocomplete="off" placeholder="请输入标题" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">ip</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{ doors_equip.ip }}" name="ip" lay-verify="title"
                               autocomplete="off" placeholder="请输入标题" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">x轴</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{ doors_equip.x }}" name="x" lay-verify="title"
                               autocomplete="off" placeholder="请输入标题"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">y轴</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{ doors_equip.y }}" name="y" lay-verify="title"
                               autocomplete="off" placeholder="请输入标题"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">z轴</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{ doors_equip.z }}" name="z" lay-verify="title"
                               autocomplete="off" placeholder="请输入标题"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">旋转x</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{ doors_equip.rx }}" name="rx" lay-verify="title"
                               autocomplete="off" placeholder="请输入标题"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">旋转y</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{ doors_equip.ry }}" name="ry" lay-verify="title"
                               autocomplete="off" placeholder="请输入标题"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">旋转z</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{ doors_equip.rz }}" name="rz" lay-verify="title"
                               autocomplete="off" placeholder="请输入标题"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">地图id</label>
                    <div class="layui-input-block">
                        <input type="text" value="{{ doors_equip.map_id }}" name="map_id" lay-verify="title"
                               autocomplete="off" placeholder="请输入标题"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">归属部门</label>
                    <div class="layui-input-block">
                        <ul id="selectParent" name="deptId" class="dtree" data-id="0"></ul>
                    </div>
                </div>
<!--                <div class="layui-form-item">-->
<!--                    <label class="layui-form-label">部门</label>-->
<!--                    <div class="layui-input-block">-->
<!--                        <ul id="selectParent" name="deptId" class="dtree" data-id="0"></ul>-->
<!--                    </div>-->
<!--                </div>-->


<!--                <div class="layui-form-item">-->
<!--                    <label class="layui-form-label">角色</label>-->
<!--                    <div class="layui-input-block">-->
<!--                        {% for role in roles %}-->
<!--                            <input{% if role.id in checked_roles %}-->
<!--                                checked-->
<!--                            {% endif %}-->
<!--                                value="{{ role.id }}" title="{{ role.name }}" type="checkbox"-->
<!--                                name="roleIds" lay-skin="primary">-->
<!--                        {% endfor %}-->
<!--                    </div>-->
<!--                </div>-->
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
                    lay-filter="user-update">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
{% include 'admin/common/footer.html' %}
<script>
  layui.use(['form', 'jquery', 'dtree'], function () {
    let form = layui.form
    let $ = layui.jquery

    let dtree = layui.dtree

    dtree.renderSelect({
      elem: '#selectParent',
      url: '/dept/tree',
      method: 'get',
      selectInputName: { nodeId: 'deptId', context: 'deptName' },
      skin: 'layui',
      dataFormat: 'list',
      response: { treeId: 'deptId', parentId: 'parentId', title: 'deptName' },
      selectInitVal: "{{ doors_equip.dept_id }}"
    })

    form.on('submit(user-update)', function (data) {
      let roleIds = ''
      $('input[type=checkbox]:checked').each(function () {
        roleIds += $(this).val() + ','
      })
      data.field.id = {{ doors_equip.id }}
      roleIds = roleIds.substr(0, roleIds.length - 1)
      data.field.roleIds = roleIds
      $.ajax({
        url: '/admin/doors_equip/update',
        data: JSON.stringify(data.field),
        dataType: 'json',
        contentType: 'application/json',
        type: 'put',
        success: function (result) {
          if (result.success) {
            layer.msg(result.msg, { icon: 1, time: 1000 }, function () {
              parent.layer.close(parent.layer.getFrameIndex(window.name))//关闭当前页
              parent.layui.table.reload('doors-table')
            })
          } else {
            layer.msg(result.msg, { icon: 2, time: 1000 })
          }
        }
      })
      return false
    })
  })
</script>
</body>
</html>